$(function () {
    vm.loadAccess();
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		showInfo:false,
		title: null,
		isUpdate:false,
		config: {settleAccess:0},
		accesses:[]
	},
	methods: {
        loadConfig:function () {
			$.getJSON("/platform/manage/payConfig/get",null,function (r) {
				if (r.code == 200){
                    vm.config = r.result;
                    $("[name='zzz']").bootstrapSwitch({
                        onText:"开启",
                        offText:"关闭",
                        state:vm.config.isOpen == '1',
                        size:"small",
                        onSwitchChange:function(event,state){
                            if(state==true){
                                vm.config['isOpen'] = '1';
                            }else{
                                vm.config['isOpen'] = '0';
                            }
                        }
                    });
				}
				else
					alert(r.message);
            })
        },
        loadAccess:function () {
            $.getJSON("/platform/manage/payConfig/getAccess",null,function (r) {
                if (r.code == 200){
                    vm.loadConfig();
                    vm.accesses = r.result;
				}else
                    alert(r.message);
            })
        },
        saveOrUpdate: function (event) {
			if (vm.config.settleAccess == 0 || vm.config.settleAccess == null){
				alert("请选择通道");
				return;
			}
			vm.config['discountEndDate'] = $('#date1').val();
			vm.config['backEndDate'] = $('#date2').val();
			// console.log("data",vm.config);
			$.ajax({
				type: "POST",
			    url: "/platform/manage/payConfig/update",
				contentType:"application/json;charset=UTF-8",
			    data: JSON.stringify(vm.config),
			    success: function(r){
			    	if(r.code == 200){
						alert('操作成功');
					}else{
						alert(r.message);
					}
				},
				error:function (e) {
			    	console.error("request error",e);
					alert("服务器繁忙");
                }
			});
		}
	}
});